/**
 * Copyright 2011 Joe Choi, All rights reserved.
 */
package tao.data.structure.tree;

import java.util.Arrays;
import java.util.List;

/**
 * The implementation of GrowableTree interface
 * 
 * @author Joe Choi
 * @version 1.0.0
 */
public class ConcreteGrowableTree<V> extends ConcreteTree<V> implements GrowableTree<V> {
	public ConcreteGrowableTree(Tree<V> tree) {
		super(tree);
	}

	public ConcreteGrowableTree(V value) {
		super(value);
	}
		
	public ConcreteGrowableTree(V value, Trees<V> trees) {
		super(value, trees);
	}
	
	public ConcreteGrowableTree(V value, Tree<V>[] trees) {
		super(value, trees);
	}

	public ConcreteGrowableTree(V value, List<Tree<V>> treeList) {
		super(value, treeList);
	}
	
	@Override
	public void add(GrowableTree<V>... tree) {
		if(tree != null) subtree.getTrees().addAll(Arrays.asList(tree));
	}

	@SuppressWarnings("unchecked")
	@Override
	public void reAdd(GrowableTree<V> tree) {
		int pos = subtree.generalizeValue().indexOf(tree.getValue());
		if(pos >=0 && pos < subtree.getTrees().size()) subtree.getTrees().remove(pos);
		add(tree);
	}
	
	@Override
	public void add(Trees<V> trees) {
		if(trees != null) subtree.getTrees().addAll(trees.generalize());
	}

	@Override
	public void add(List<GrowableTree<V>> treeList) {
		if(treeList != null) subtree.getTrees().addAll(treeList);
	}
}